﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class TrackList : System.Web.UI.Page
{
    public string LstMusic { get; set; }
    static int alid;

    protected void Page_Load(object sender, EventArgs e)
    {
        string alid_s = Request.QueryString["alid"];
        bool t = Int32.TryParse(alid_s, out alid);

        if (t)
        {
            LoadAlbumMusic(alid);
        }
    }

    private void LoadAlbumMusic(int albumid)
    {
        Sharemp3DataContext db = new Sharemp3DataContext();
        StringBuilder buff = new StringBuilder();

        var lst = (from i in db.Musics
                   where i.AlbumID == albumid
                   select new
                   {
                       FilePath = i.FilePath,
                       OGA = i.OGA,
                       Title = i.Title,
                       ArtistName = i.Album.Artist.ArtistName,
                       Rating = i.Rating,
                       Buy = i.Buy,
                       Price = i.Price,
                       Duration = i.Duration,
                       Cover = i.Cover
                   }).Take(3);
        foreach (var music in lst)
        {
            buff.Append("{mp3:'" + music.FilePath + "',oga:'" + music.OGA + "',title:'" + music.Title + "',artist:'" + music.ArtistName + "',rating:" + music.Rating + ",buy:'" + music.Buy + "',price:'" + music.Price + "',duration:'" + music.Duration + "',cover:'" + music.Cover + "'},");
        }
        if (buff.Length != 0)
        {
            LstMusic = buff.ToString().Substring(0, buff.Length - 2) + "}";
        }

        Album selectedAlbum = db.Albums.Where(i => i.AlbumID == albumid).First();
        lblTitle.InnerText = "Album \"" + selectedAlbum.AlbumName + "\"";
        lblArtistName.InnerText = "Album by \"" + selectedAlbum.Artist.ArtistName + "\"";

        var album = db.Albums.Where(i => i.ArtistID == selectedAlbum.ArtistID).Take(10);
        Rpt_AlbumArtist.DataSource = album;
        Rpt_AlbumArtist.DataBind();
    }
}